/**create by liuhua at 2019年7月23日 下午3:12:57**/
package com.star.truffle.module.fzjz.properties;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.star.truffle.module.fzjz.domain.Area;

import lombok.Data;

@Data
@Component
@ConfigurationProperties(prefix = "fzjz-cfg")
public class FzjzCfg {

  private List<Area> areas;
  
  public Area getAreaBy(Integer areaId) {
    if(null == areaId) {
      return null;
    }
    if(null != areas && ! areas.isEmpty()) {
      return areas.stream().filter(area -> area.getAreaId() == areaId.intValue()).findAny().orElse(null);
    }
    return null;
  }
  
  public Area getAreaBy(String areaCode) {
    if(StringUtils.isBlank(areaCode)) {
      return null;
    }
    if(null != areas && ! areas.isEmpty()) {
      return areas.stream().filter(area -> areaCode.equals(area.getAreaCode())).findAny().orElse(null);
    }
    return null;
  }
  
  public Area getAreaByName(String areaName) {
    if(StringUtils.isBlank(areaName)) {
      return null;
    }
    if(null != areas && ! areas.isEmpty()) {
      return areas.stream().filter(area -> areaName.equals(area.getAreaName())).findAny().orElse(null);
    }
    return null;
  }
}
